Skip to content

Paste at the current cursor and clean up transcripts - #11

Open
ichen27 wants to merge 2 commits into
mainfrom
fix/paste-at-cursor
Open

ichen27 wants to merge 2 commits into
mainfrom
fix/paste-at-cursor

Conversation

@ichen27

@ichen27 ichen27 commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Problem

Dictations sometimes did not paste. Insertion refused, and only copied the text to the clipboard, when any of these happened during transcription:

  • the field's text changed (autosave, other edits, a live terminal buffer),
  • the cursor moved,
  • the focused accessibility element was rebuilt (common in web and Electron editors such as Slack, Notion, ChatGPT and Gmail), or
  • the app didn't expose a value or selection range.

The README also told users to "keep the selected field and cursor unchanged", which is easy to break without noticing. Raw Whisper output also kept hesitations ("um", "uh"), stutters and stray spacing, and ignored the text around the cursor.

Change

Paste at the current cursor (TextInsertion.swift, ClearFlowCore/Insertion.swift)

  • The app in front when dictation starts is the target. When the transcript is ready, it's pasted at that app's current cursor, as long as the app is still in front and focused on an editable, non-password control.
  • Contenteditable web editors (AXEditableAncestor) and custom text views (settable value plus a selection range) count as editable. Sliders and buttons do not.
  • Fixed sleeps (180 ms for activation, 500 ms for paste) are replaced by polling with timeouts.
  • Command-V waits up to 1.5 s for shortcut modifiers to be released, so a held key can't turn it into another command.
  • Clipboard restoration rules are unchanged. The previous clipboard comes back only after the paste is observed, and only if the clipboard wasn't changed in the meantime.

Rule-based cleanup (ClearFlowCore/TranscriptCleanup.swift, on by default, Settings → General)

  • Removes um, uh, erm and hmm, collapses stutters ("I I think" becomes "I think"), and fixes spacing and comma artifacts. Grammatical repeats such as "had had" and "that that" are kept, as are emphatic ones like "very very".
  • A standalone "new line" or "new paragraph" becomes a line break. "A new line of products" is left alone.
  • At paste time, the text is fitted to the cursor: leading and trailing spaces, mid-sentence lowercase (but "I", acronyms and words like "iPhone" keep their capitals), and no full stop before lowercase text that follows.
  • Wording is not rewritten.

Validation

  • scripts/test-native.sh, scripts/test-shortcut-registration.sh, scripts/build-app.sh and scripts/check-distribution.py all pass locally.
  • New core checks cover editability, paste prediction (including UTF-16 emoji offsets), cleanup cases taken from real Whisper output on the local service, and cursor fitting.
  • Not verified on a device: cross-app paste in real editors needs the Accessibility permission, which CI can't grant. Try Slack, Notion, a browser textarea, Terminal and Notes.

Risks

  • Typing elsewhere in the same app while transcription runs now inserts at the new cursor. This is intentional and was the requested behavior.
  • Mid-sentence lowercasing can lowercase a proper noun at the start of a dictation ("and john said"). Turn cleanup off if that's a problem.

Insertion refused, and only copied to the clipboard, whenever the field text,
cursor or focused element changed during transcription, or when an app did not
expose cursor details. Web and Electron editors rebuild elements, so pastes
failed intermittently. Now the transcript is pasted at the cursor of the app
that was in front, provided it is still in front, focused on an editable,
non-password control. Activation and paste confirmation poll instead of fixed
sleeps, held shortcut modifiers are released first, and contenteditable and
custom text views count as editable.
Remove hesitations (um, uh, erm, hmm), stutters and stray spacing; turn a
standalone "new line" or "new paragraph" into line breaks; and at paste time
match leading/trailing spaces, mid-sentence lowercase and a premature full stop
to the surrounding text. Wording is not rewritten. On by default with a
General setting to turn it off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant